from mitmproxy import http

class ModifyFlow:
    def request(self, flow: http.HTTPFlow) -> None:
        # 修改请求头
        flow.request.headers["X-Custom-Header"] = "Hello"

    def response(self, flow: http.HTTPFlow) -> None:
        # 修改响应内容
        if flow.request.url.endswith("/example"):
            flow.response.text = "Hello, modified response!"

addons = [ModifyFlow()]